package com.itheima11;

import java.util.Arrays;

/**
 * @author Xiao
 * @date 2021/7/22
 */
public class FactorialDemo05_classmate {
    public static void main(String[] args) {
        int[] arr = {6, 1, 2, 7, 9, 3, 4, 5, 10, 8};
        arrfast(arr, 0, arr.length - 1);
        System.out.println(Arrays.toString(arr));
    }

    private static void arrfast(int[] arr, int left, int right) {
        if (left > right) {
            return;
        }
        int left0 = left;
        int right0 = right;
        int baseNum = arr[left0];
        while (left != right) {
            while (arr[right] >= baseNum && right > left) {
                right--;
            }
            while (baseNum >= arr[left] && right > left) {
                left++;
            }
            int temp = arr[right];
            arr[right] = arr[left];
            arr[left] = temp;
        }
        int middle = arr[left];
        arr[left] = arr[left0];
        arr[left0] = middle;
        arrfast(arr, left0, left - 1);
        arrfast(arr, left + 1, right0);
    }

}
